/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * StoiPanel.java
 *
 * Created on Apr 6, 2011, 10:16:08 AM
 */

package gui;

import java.awt.Image;
import javax.swing.ImageIcon;

/**
 *
 * @author Donald
 */
public class StoiPanel extends javax.swing.JPanel {

	final static int IMG_WIDTH = 80;
	final static int IMG_HEIGHT = -1;//Not used to maintain aspect ratio
	ImageIcon image;
	
	
    /** Creates new form StoiPanel */
    public StoiPanel(String Molecule,double mol,double mass,double volume) {
        initComponents();
        
        MoleculeLabel.setText(Molecule);
        MolLabel.setText(mol + " mol");
        MassLabel.setText(mass + " g");
        VolumeLabel.setText(volume + " L (gas @ stp)");
    }
    
    public void setMolImage(ImageIcon image){
    	this.image = image;
    	ImageIcon resizedImage = resizeImage(image);
    	ImageLabel.setIcon(resizedImage);
    	ImageLabel.validate();
    }
    private static ImageIcon resizeImage(ImageIcon originalImage){
    	Image img = originalImage.getImage();  
    	Image newimg = img.getScaledInstance(IMG_WIDTH, IMG_HEIGHT,  java.awt.Image.SCALE_SMOOTH);  
    	ImageIcon newIcon = new ImageIcon(newimg);  
    	return newIcon;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        MoleculeLabel = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        MolLabel = new javax.swing.JLabel();
        MassLabel = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        VolumeLabel = new javax.swing.JLabel();
        ImageLabel = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        setPreferredSize(new java.awt.Dimension(305, 124));

        MoleculeLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        MoleculeLabel.setText("MOLECULE");

        jLabel2.setText("Quantity");

        MolLabel.setText("jLabel3");

        MassLabel.setText("jLabel4");

        jLabel5.setText("Mass");

        jLabel6.setText("Volume");

        VolumeLabel.setText("jLabel7");

        ImageLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        ImageLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel2))
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(MassLabel)
                            .addComponent(MolLabel)
                            .addComponent(VolumeLabel)))
                    .addComponent(MoleculeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                .addComponent(ImageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(25, 25, 25))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(MoleculeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(MolLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(MassLabel)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(VolumeLabel))
                .addContainerGap(37, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(ImageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel ImageLabel;
    private javax.swing.JLabel MassLabel;
    private javax.swing.JLabel MolLabel;
    private javax.swing.JLabel MoleculeLabel;
    private javax.swing.JLabel VolumeLabel;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    // End of variables declaration//GEN-END:variables

}
